<?php
class CiuacademicperiodsController extends AppController {
  var $components = array('Session');
  var $name = 'Ciuacademicperiods';

  function index() {
    $this->Ciuacademicperiod->recursive = 0;
    $this->set('ciuacademicperiods', $this->paginate());
  }

  function view($id = null) {
    if (!$id) {
      $this->Session->setFlash(__('Invalid ciuacademicperiod', true));
      $this->redirect(array('action' => 'index'));
    }
    $this->set('ciuacademicperiod', $this->Ciuacademicperiod->read(null, $id));
  }

  function add() {
    if (!empty($this->data)) {
      $this->Ciuacademicperiod->updateAll(
                                          array('Ciuacademicperiod.isactive'=>"'0'")
                                          );
      $this->Ciuacademicperiod->create();
      $this->data['Ciuacademicperiod']['isactive']=1;
      if ($this->Ciuacademicperiod->save($this->data)) {
        $this->Session->setFlash(__('The ciuacademicperiod has been saved', true));
        $this->redirect(array('action' => 'index'));
      } else {
        $this->Session->setFlash(__('The ciuacademicperiod could not be saved. Please, try again.', true));
      }
    }
  }

  function edit($id = null) {
    if (!$id && empty($this->data)) {
      $this->Session->setFlash(__('Invalid ciuacademicperiod', true));
      $this->redirect(array('action' => 'index'));
    }
    if (!empty($this->data)) {
      $this->Ciuacademicperiod->updateAll(
                                          array('Ciuacademicperiod.isactive'=>"'0'")
                                          );
      $this->data['Ciuacademicperiod']['isactive']=1;
      if ($this->Ciuacademicperiod->save($this->data)) {
        $this->Session->setFlash(__('The ciuacademicperiod has been saved', true));
        $this->redirect(array('action' => 'index'));
      } else {
        $this->Session->setFlash(__('The ciuacademicperiod could not be saved. Please, try again.', true));
      }
    }
    if (empty($this->data)) {
      $this->data = $this->Ciuacademicperiod->read(null, $id);
    }
  }

  function delete($id = null) {
    if (!$id) {
      $this->Session->setFlash(__('Invalid id for ciuacademicperiod', true));
      $this->redirect(array('action'=>'index'));
    }
    if ($this->Ciuacademicperiod->delete($id)) {
      $this->Session->setFlash(__('Ciuacademicperiod deleted', true));
      $this->redirect(array('action'=>'index'));
    }
    $this->Session->setFlash(__('Ciuacademicperiod was not deleted', true));
    $this->redirect(array('action' => 'index'));
  }
  
}
